//
// Created by none98 on 2021/9/10.
//

#ifndef LOGINSERVER_SELECTOR_H
#define LOGINSERVER_SELECTOR_H


#include <unordered_map>
#include <sys/epoll.h>
#include <unistd.h>
#include <mutex>
#include <vector>


class Channel;
class Selector {
    friend class EventLoop;
public:
    static const unsigned int READ = EPOLLIN;
    static const unsigned int WRITE = EPOLLOUT;
    static const unsigned int ERROR = EPOLLERR;
    static const unsigned int EDGE_TRIEGER = EPOLLET;

    Selector(){
        fd = epoll_create(1);
    }
    ~Selector(){
        close(fd);
    }

    int RegisterChannel(Channel* channel);
    int UpdateChannel(Channel* channel);
    int DeleteChannel(Channel* channel);


private:
    int fd;
    std::vector<Channel*> Select(int timeout);
};



#endif //LOGINSERVER_SELECTOR_H
